package gwtI18nEditor.resources;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public enum Language {
	ARABIC    ("ar", "Arabic"    , Country.ALGERIA, Country.BAHRAIN, Country.EGYPT, Country.IRAQ, Country.JORDAN, Country.KUWAIT, Country.LEBANON, Country.LIBYA, Country.MOROCCO, Country.OMAN, Country.QATAR, Country.SAUDI_ARABIA, Country.SUDAN, Country.SYRIA, Country.TUNISIA, Country.UNITED_ARAB_EMIRATES, Country.YEMEN),
	BELARUSIAN("be", "Belarusian", Country.BELARUS),
	BULGARIAN ("bg", "Bulgarian" , Country.BULGARIA),
	CATALAN   ("ca", "Catalan"   , Country.SPAIN),
	CZECH     ("cs", "Czech"     , Country.CZECH_REPUBLIC),
	DANISH    ("da", "Danish"    , Country.DENMARK),
	GERMAN    ("de", "German"    , Country.AUSTRIA, Country.GERMANY),
	GREEK     ("el", "Greek"     , Country.CYPRUS, Country.GREECE),
	ENGLISH   ("en", "English"   , Country.AUSTRALIA, Country.CANADA, Country.INDIA, Country.IRELAND, Country.MALTA, Country.NEW_ZEALAND, Country.PHILIPPINES, Country.SOUTH_AFRICA, Country.UNITED_KINGDOM, Country.UNITED_STATES),
	SPANISH   ("es", "Spanish"   , Country.ARGENTINA, Country.BOLIVIA, Country.CHILE, Country.COLOMBIA, Country.COSTA_RICA, Country.DOMINICAN_REPUBLIC, Country.ECUADOR, Country.EL_SALVADOR, Country.GUATEMALA, Country.HONDURAS, Country.MEXICO, Country.NICARAGUA, Country.PANAMA, Country.PARAGUAY, Country.PERU, Country.PUERTO_RICO, Country.URUGUAY, Country.VENEZUELA),
	ESTONIAN  ("et", "Estonian"  , Country.ESTONIA),
	FINNISH   ("fi", "Finnish"   , Country.FINLAND),
	FRENCH    ("fr", "French"    , Country.FRANCE, Country.LUXEMBOURG, Country.SWITZERLAND),
	IRISH     ("ga", "Irish"     ),
	HINDI     ("hi", "Hindi"     ),
	CROATIAN  ("hr", "Croatian"  , Country.CROATIA),
	HUNGARIAN ("hu", "Hungarian" , Country.HUNGARY),
	INDONESIAN("in", "Indonesian", Country.INDONESIA),
	ICELANDIC ("is", "Icelandic" , Country.ICELAND),
	ITALIAN   ("it", "Italian"   , Country.ITALY),
	HEBREW    ("iw", "Hebrew"    , Country.ISRAEL),
	JAPANESE  ("ja", "Japanese"  , Country.JAPAN),
	KOREAN    ("ko", "Korean"    , Country.SOUTH_KOREA),
	LITHUANIAN("lt", "Lithuanian", Country.LITHUANIA),
	LATVIAN   ("lv", "Latvian"   , Country.LATVIA),
	MACEDONIAN("mk", "Macedonian", Country.MACEDONIA),
	MALAY     ("ms", "Malay"     , Country.MALAYSIA),
	MALTESE   ("mt", "Maltese"   ),
	DUTCH     ("nl", "Dutch"     , Country.BELGIUM, Country.NETHERLANDS),
	NORWEGIAN ("no", "Norwegian" , Country.NORWAY),
	POLISH    ("pl", "Polish"    , Country.POLAND),
	PORTUGUESE("pt", "Portuguese", Country.BRAZIL, Country.PORTUGAL),
	ROMANIAN  ("ro", "Romanian"  , Country.ROMANIA),
	RUSSIAN   ("ru", "Russian"   , Country.RUSSIA),
	SLOVAK    ("sk", "Slovak"    , Country.SLOVAKIA),
	SLOVENIAN ("sl", "Slovenian" , Country.SLOVENIA),
	ALBANIAN  ("sq", "Albanian"  , Country.ALBANIA),
	SERBIAN   ("sr", "Serbian"   , Country.BOSNIA_AND_HERZEGOVINA, Country.MONTENEGRO, Country.SERBIA_AND_MONTENEGRO, Country.SERBIA),
	SWEDISH   ("sv", "Swedish"   , Country.SWEDEN),
	THAI      ("th", "Thai"      , Country.THAILAND),
	TURKISH   ("tr", "Turkish"   , Country.TURKEY),
	UKRAINIAN ("uk", "Ukrainian" , Country.UKRAINE),
	VIETNAMESE("vi", "Vietnamese", Country.VIETNAM),
	CHINESE   ("zh", "Chinese"   , Country.CHINA, Country.HONG_KONG, Country.SINGAPORE, Country.TAIWAN);

	private static final Map<String, Language> index = buildMap();
	
	private final String               code;
	private final String               name;
	private final List<Country>        countries;
	private final Map<String, Country> countryIndex;
	
	Language(String code, String name, Country... countries) {
		this.code         = code;
		this.name         = name;
		this.countries    = Arrays.asList(countries);
		this.countryIndex = new HashMap<String, Country>();
		for (Country country: countries) {
			countryIndex.put(country.getCode(), country);
		}
	}

	private static Map<String, Language> buildMap() {
		Map<String, Language> result = new HashMap<String, Language>();
		for (Language language: Language.values()) {
			result.put(language.code, language);
		}
		return result;
	}

	public String getCode() {
		return code;
	}

	public String getName() {
		return name;
	}

	public List<Country> getCountries() {
		return countries;
	}
	
	public static Language get(String code) {
		return index.get(code);
	}
	
	public Country getCountry(String code) {
		return countryIndex.get(code);
	}
}
